
Class('addDeviceinfo', 'linb.Com',{
    Instance:{
        //base Class for this com
        base:["linb.UI.Dialog"], 
        //requried class for this com
        required:["linb.UI.Dialog", "linb.UI.Label", "linb.UI.Group", "linb.UI.Button", "linb.UI.Input", "linb.UI.ComboInput", "linb.DataBinder"], 

        properties:{}, 
        events:{}, 
        adself:null, 
        parents : null,
        iniResource:function(com, threadid){
        }, 
        iniComponents:function(){
            // [[code created by jsLinb UI Builder
            var host=this, children=[], append=function(child){children.push(child.get(0))};
            
            append((new linb.DataBinder)
                .host(host,"databinder1")
                .setName("data_device")
            );
            
            append((new linb.UI.Dialog)
                .host(host,"dialog_add_device")
                .setLeft(100)
                .setTop(20)
                .setWidth(696)
                .setHeight(415)
                .setCaption("增加设备")
                .onRender("_dialog_add_device_onrender")
                .beforeDestroy("_dialog_add_device_beforedestroy")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label1")
                .setLeft(10)
                .setTop(10)
                .setWidth(60)
                .setCaption("设备IP")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label2")
                .setLeft(230)
                .setTop(10)
                .setWidth(60)
                .setCaption("设备类型")
            );
            
            host.dialog_add_device.append((new linb.UI.Group)
                .host(host,"snmpgroup")
                .setLeft(10)
                .setTop(30)
                .setWidth(660)
                .setHeight(80)
                .setCaption("SNMP信息")
                .setToggleBtn(false)
            );
            
            host.snmpgroup.append((new linb.UI.Label)
                .host(host,"label3")
                .setLeft(140)
                .setTop(5)
                .setWidth(40)
                .setCaption("端口")
            );
            
            host.snmpgroup.append((new linb.UI.Label)
                .host(host,"label4")
                .setLeft(10)
                .setTop(5)
                .setWidth(40)
                .setCaption("版本")
            );
            
            host.snmpgroup.append((new linb.UI.Label)
                .host(host,"label5")
                .setLeft(270)
                .setTop(5)
                .setWidth(60)
                .setCaption("读口令")
            );
            
            host.snmpgroup.append((new linb.UI.Label)
                .host(host,"label6")
                .setLeft(430)
                .setTop(5)
                .setWidth(60)
                .setCaption("写口令")
            );
            
            host.snmpgroup.append((new linb.UI.Button)
                .host(host,"btnGet")
                .setLeft(530)
                .setTop(34)
                .setCaption("读取设备信息")
                .onClick("_btnget_onclick")
            );
            
            host.snmpgroup.append((new linb.UI.Input)
                .host(host,"port")
                .setDataBinder("data_device")
                .setDataField("port")
                .setLeft(188)
                .setTop(2)
                .setWidth(80)
            );
            
            host.snmpgroup.append((new linb.UI.Input)
                .host(host,"rcommunity")
                .setDataBinder("data_device")
                .setDataField("rcommunity")
                .setLeft(330)
                .setTop(2)
                .setWidth(110)
            );
            
            host.snmpgroup.append((new linb.UI.Input)
                .host(host,"wcommunity")
                .setDataBinder("data_device")
                .setDataField("wcommunity")
                .setLeft(490)
                .setTop(2)
            );
            
            host.snmpgroup.append((new linb.UI.ComboInput)
                .host(host,"version")
                .setDataBinder("data_device")
                .setDataField("version")
                .setLeft(50)
                .setTop(2)
                .setWidth(90)
                .setHeight(20)
                .setItems([{"id":1, "caption":"SNMP v1"}, {"id":2, "caption":"SNMP v2"}])
                .setValue("1")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label13")
                .setLeft(10)
                .setTop(120)
                .setWidth(70)
                .setCaption("设备名称")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label14")
                .setLeft(10)
                .setTop(180)
                .setWidth(70)
                .setCaption("设备描述")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label15")
                .setLeft(20)
                .setTop(270)
                .setWidth(60)
                .setCaption("产品描述")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label16")
                .setLeft(10)
                .setTop(150)
                .setWidth(70)
                .setCaption("设备OID")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label17")
                .setLeft(30)
                .setTop(240)
                .setWidth(50)
                .setCaption("产品ID")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label18")
                .setLeft(320)
                .setTop(120)
                .setWidth(60)
                .setCaption("放置地点")
            );
            
            host.dialog_add_device.append((new linb.UI.Button)
                .host(host,"btnSave")
                .setLeft(260)
                .setTop(340)
                .setCaption("保存并新增")
                .onClick("_btnsave_onclick")
            );
            
            host.dialog_add_device.append((new linb.UI.Button)
                .host(host,"btnCancel")
                .setLeft(540)
                .setTop(340)
                .setCaption("退出")
                .onClick("_btncancel_onclick")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label19")
                .setLeft(320)
                .setTop(150)
                .setWidth(60)
                .setCaption("启动时间")
            );
            
            host.dialog_add_device.append((new linb.UI.Label)
                .host(host,"label20")
                .setLeft(580)
                .setTop(150)
                .setWidth(40)
                .setCaption("服务ID")
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"ip")
                .setDataBinder("data_device")
                .setDataField("ip")
                .setLeft(70)
                .setTop(10)
                .setWidth(160)
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"name")
                .setDataBinder("data_device")
                .setDataField("name")
                .setLeft(80)
                .setTop(119)
                .setWidth(240)
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"location")
                .setDataBinder("data_device")
                .setDataField("location")
                .setLeft(380)
                .setTop(120)
                .setWidth(280)
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"device_id")
                .setDataBinder("data_device")
                .setDataField("device_id")
                .setLeft(80)
                .setTop(150)
                .setWidth(240)
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"sysUptime")
                .setDataBinder("data_device")
                .setDataField("sysUptime")
                .setLeft(380)
                .setTop(150)
                .setWidth(190)
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"sysService")
                .setDataBinder("data_device")
                .setDataField("sysService")
                .setLeft(620)
                .setTop(150)
                .setWidth(40)
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"product_id")
                .setDataBinder("data_device")
                .setDataField("product_id")
                .setLeft(80)
                .setTop(240)
                .setWidth(300)
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"product_desc")
                .setDataBinder("data_device")
                .setDataField("product_desc")
                .setLeft(80)
                .setTop(270)
                .setWidth(580)
                .setHeight(50)
                .setMultiLines(true)
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"descri")
                .setDataBinder("data_device")
                .setDataField("descri")
                .setLeft(80)
                .setTop(180)
                .setWidth(580)
                .setHeight(50)
            );
            
            host.dialog_add_device.append((new linb.UI.ComboInput)
                .host(host,"dtype")
                .setDataBinder("data_device")
                .setDataField("dtype")
                .setLeft(290)
                .setTop(10)
                .setItems([{"id":0, "caption":"主机"}, {"id":1, "caption":"网络设备"}])
            );
            
            host.dialog_add_device.append((new linb.UI.Input)
                .host(host,"id")
                .setDataBinder("data_device")
                .setDataField("id")
                .setLeft(430)
                .setTop(10)
                .setVisibility("hidden")
            );
            
            host.dialog_add_device.append((new linb.UI.Button)
                .host(host,"button20")
                .setLeft(400)
                .setTop(340)
                .setCaption("保存")
                .onClick("_button20_onclick")
            );
            
            return children;
            // ]]code created by jsLinb UI Builder
        }, 
        iniExComs:function(com, hreadid){
        }, 
        setWhoisParent:function(myparents) {
            parents = myparents;
        }, 
        _dialog_add_device_beforedestroy:function (profile) {
            if (parents != null) {
                oo = _.unserialize(parents.menubar1.getTagVar());
                oo.madd_device = 0;
                parents.menubar1.setTagVar(_.serialize(oo));
            }
            linb.DataBinder.destroyAll();
            return true;
        },        
        SNMPObject:function() {
            this.ip = '127.0.0.1';
            this.dtype = 1;
            this.version = 1;
            this.port = 161;
            this.rcommunity = 'public';
            this.wcommunity = 'public';
        }, 
        SNMPGetInfo:function(cmd,datas) {
            linb.request("/NetDM4Web/devicemanager.do","cmd="+cmd+"&datas="+datas,
            function(rep, type){
                returanpkg = _.unserialize(rep);
                if (returanpkg.code == 0) {
                    so = _.unserialize(returanpkg.datas);
                    adself.databinder1.resetValue(so);
                }
                if (returanpkg.code < 0){
                    linb.UI.Dialog.alert('提示',returanpkg.messages);
                }

            },
            function() {
                linb.UI.Dialog.alert('提示','网络连接出现问题，无法获得数据，请稍候重试');
            });
        }, 
        _btnget_onclick:function (profile, e, src, value) {
            so = new adself.SNMPObject();
            so.ip = adself.ip.updateValue().getValue();
            so.dtype = adself.dtype.updateValue().getValue();
            so.version = adself.version.updateValue().getValue();
            so.port = adself.port.updateValue().getValue();
            so.rcommunity = adself.rcommunity.updateValue().getValue();
            so.wcommunity = adself.wcommunity.updateValue().getValue();
            adself.SNMPGetInfo('fd',_.serialize(so));
        }, 
        SaveData:function(cmd,datas,fun){
            linb.request("/NetDM4Web/devicemanager.do","cmd="+cmd+"&datas="+datas,
            function(rep, type){
                returanpkg = _.unserialize(rep);
                if (returanpkg.code == 0) {
                	linb.UI.Dialog.alert('提示',returanpkg.messages);
                	fun;
                }
                if (returanpkg.code < 0){
                    linb.UI.Dialog.alert('提示',returanpkg.messages);
                }

            },
            function() {
                linb.UI.Dialog.alert('提示','网络连接出现问题，无法获得数据，请稍候重试');
            });
        }, 
        _btnsave_onclick:function (profile, e, src, value) {
            datas = _.serialize(adself.databinder1.getValue());
            adself.SaveData('save',datas,adself.inputinit());
        }, 
        _btncancel_onclick:function (profile, e, src, value) {
            adself.dialog_add_device.close();
        },
        inputinit:function() {
            adself.id.setUIValue(-1).updateValue();
            adself.ip.setUIValue('127.0.0.1').updateValue();
            adself.dtype.setUIValue(1).updateValue();
            adself.version.setUIValue(1).updateValue();
            adself.port.setUIValue(161).updateValue();
            adself.rcommunity.setUIValue('public').updateValue();
            adself.wcommunity.setUIValue('public').updateValue();
            adself.name.setUIValue('').updateValue();
            adself.location.setUIValue('').updateValue();
            adself.device_id.setUIValue('').updateValue();
            adself.sysUptime.setUIValue('').updateValue();
            adself.sysService.setUIValue('').updateValue();
            adself.descri.setUIValue('').updateValue();
            adself.product_id.setUIValue('').updateValue();
            adself.product_desc.setUIValue('').updateValue();            
        }, 
        _dialog_add_device_onrender:function (profile) {
            adself = this;
            adself.inputinit();
        }, 
        _button20_onclick:function (profile, e, src, value) {
            datas = _.serialize(adself.databinder1.getValue());
            adself.SaveData('save',datas,adself.dialog_add_device.close());
        }
    }
});